$(function () {
    //======================
    //======设置查询条件========
    //======================
    //搜索按钮
    $("#yjykhhz_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams:{
                year:$("#yjykhhz_year").val(),
                month:$("#yjykhhz_month").val()
            }});
    });

//======================
//========统计列表========
//======================
    var columns = [
        [
            {field:'gs_name', title:'公司名称', width:150, rowspan:2, align:'center'},
            {title:'经营收入', colspan:3, width:100, align:'right'},
            {title:'净利润', colspan:3, width:100, align:'right'},
            {field:'khhkl', title:'考核回款率', rowspan:2, align:'right', formatter:function (value) {
                var val = formatJe2(value, ",");
                return val;
            }, width:150},
            {field:'ywcb', title:'业务成本', rowspan:2, align:'right', formatter:function (v, r, i) {
                var color = "#0000ff;";
                if (v && r.gs_name != '合计') {
                    if (v < 0) color = "red;";
                    return "<a href='javascript:void(0)' style='color:{0}' class='ywcb' gsid='{1}'>{2}</a>".stringFormat(color, r.gs_id, formatSl2(v, ",", "."));
                } else {
                    return formatSl2(v, ",", ".");
                }
            }, width:150},
            {field:'ml', title:'毛利', rowspan:2, align:'right', formatter:function (v, r, i) {
                var color = "#0000ff;";
                if (v && r.gs_name != '合计') {
                    if (v < 0) color = "red;";
                    return "<a href='javascript:void(0)' style='color:{0}' class='ml' gsid='{1}'>{2}</a>".stringFormat(color, r.gs_id, formatSl2(v, ",", "."));
                } else {
                    return formatSl2(v, ",", ".");
                }
            }, width:150},
            {field:'zjcb', title:'资金成本', rowspan:2, align:'right', formatter:function (v, r, i) {
                var color = "#0000ff;";
                if (v && r.gs_name != '合计') {
                    if (v < 0) color = "red;";
                    return "<a href='javascript:void(0)' style='color:{0}' class='zjcb' gsid='{1}'>{2}</a>".stringFormat(color, r.gs_id, formatSl2(v, ",", "."));
                } else {
                    return formatSl2(v, ",", ".");
                }
            }, width:150},
            {field:'sf', title:'税费', rowspan:2, align:'right', formatter:function (value) {
                var val = formatJe2(value, ",");
                return val;
            }, width:150},
            {field:'glcb', title:'管理成本', rowspan:2, align:'right', formatter:function (value) {
                var val = formatJe2(value, ",");
                return val;
            }, width:150},
            {field:'rlzycb', title:'人力资源成本', rowspan:2, align:'right', formatter:function (value) {
                var val = formatJe2(value, ",");
                return val;
            }, width:150}
        ],
        [

            {field:'jysr_sxsr', title:'实现收入', width:150, formatter:function (v, r, i) {
                var color = "#0000ff;";
                if (v && r.gs_name != '合计') {
                    if (v < 0) color = "red;";
                    return "<a href='javascript:void(0)' style='color:{0}' class='jysr_sxsr' gsid='{1}'>{2}</a>".stringFormat(color, r.gs_id, formatSl2(v, ",", "."));
                } else {
                    return formatSl2(v, ",", ".");
                }
            }, align:'right'},
            {field:'jysr_srzb', title:'收入指标', width:150, formatter:function (v, r, i) {
                return formatSl2(v, ",", ".");
            }, align:'right'},
            {field:'jysr_wcl', title:'完成率', width:150, formatter:function (v, r, i) {
                return formatSl2(v, ",", ".");
            }, align:'right'},
            {field:'jlr_sxlr', title:'实现利润', width:150, formatter:function (v, r, i) {
                return formatSl2(v, ",", ".");
            }, align:'right'},
            {field:'jlr_jlzb', title:'净利指标', width:150, formatter:function (v, r, i) {
                return formatSl2(v, ",", ".");
            }, align:'right'},
            {field:'jlr_wcl', title:'完成率', align:'right', formatter:function (v, r, i) {
                return formatSl2(v, ",", ".");
            }, width:150}
        ]
    ];

    var grid = $('#yjykhhz_grid').datagrid({
        url:$.webPath() + '/tjbb/yjykhhz/yjykhhzList',
        toolbar:"#yjykhhz_toolbar",
        // pagination: true,
        rownumbers:true,
        singleSelect:true,
        collapsible:true,
        fit:true,
        fitColumns:false,
        pageNumber:1,
        showFooter:true,
        queryParams:{
            year:$("#yjykhhz_year").val(),
            month:$("#yjykhhz_month").val()
        },
        onLoadSuccess:function () {
            $(".jysr_sxsr").unbind("click").bind("click", function () {
                showYjykhhzDetail('实现收入', $.webPath() + "/tjbb/yjykhhz/sjsr", $(this).attr("gsid"));
            });
            $(".ywcb").unbind("click").bind("click", function () {
                showYjykhhzDetail('业务成本', $.webPath() + "/tjbb/yjykhhz/sjsr", $(this).attr("gsid"));
            });
            $(".ml").unbind("click").bind("click", function () {
                showYjykhhzDetail('毛利', $.webPath() + "/tjbb/yjykhhz/sjsr", $(this).attr("gsid"));
            });
            $(".zjcb").unbind("click").bind("click", function () {
                showYjykhhzDetail('资金成本', $.webPath() + "/tjbb/yjykhhz/zjcb", $(this).attr("gsid"));
            });
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
        columns:columns
    });


    var showYjykhhzDetail = function (title, url, gsid) {
        var win = $.window({
            title:title,
            width:1050,
            height:470,
            cache:false,
            iconCls:'icon-tip',
            url:url + "?gsid=" + gsid + "&year=" + $("#yjykhhz_year").val() + "&month=" + $("#yjykhhz_month").val(),
            modal:true,
            buttons:[]
        });
    }

});


//利润参数按钮弹框
function lrscShowDaliog() {
    var win = $.window({
        title:'利润参数',
        width:915,
        height:450,
        cache:false,
        url:$.webPath() + "/tjbb/yjykhhz/lrcs_content",
        modal:true
    });
}

